﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils;

public partial class coupon_index : FBasePage
{
   // Fields

    public string consum = "N";
    public Maticsoft.BLL.Coupon couponbll = new Maticsoft.BLL.Coupon();
    public List<Maticsoft.Model.Coupon> couponlist = new List<Maticsoft.Model.Coupon>();
  
    public string pagenum = "1";
    public string strpage;
    public Maticsoft.BLL.UserInfo userbll = new Maticsoft.BLL.UserInfo();

    // Methods
    public void Getcoupon()
    {
        int num;
        string whereString = string.Format(" User_id='{0}' and Consume='{1}'", this.userbll.Getuserid(base.UserName), this.consum);
        if (this.consum == "expire")
        {
            whereString = "User_id='" + this.userbll.Getuserid(base.UserName) + "' and Expire_time<GetDate()";
        }
        this.couponlist = this.couponbll.SearchCoupon(30, Convert.ToInt32(this.pagenum), "*", "Create_time desc", whereString, out num);
        if (this.couponlist.Count == 0)
        {
            this.strpage = "对不起，没有相关数据";
        }
        else if (num >= 30)
        {
            this.strpage = this.couponbll.GetCouponPageStr(num, Convert.ToInt32(this.pagenum), 30, this.consum);
        }
    }

    public string GetStyle(string s, string style)
    {
        string str = "";
        if (s == style)
        {
            str = "class='current'";
        }
        return str;
    }

    public string GetTeam(string id)
    {
        string title = "";
        Maticsoft.Model.Team model = new Maticsoft.Model.Team();
        model = new Maticsoft.BLL.Team().GetModel(Convert.ToInt32(id));
        if (model != null)
        {
            title = model.Title;
        }
        return title;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.MyWebside1.Select = "coupon";
        if (!(this.Page.User.Identity.IsAuthenticated && !(this.Page.User.Identity.Name == "")))
        {
            base.Response.Redirect("/account/Login.aspx");
        }
        if (base.Request["pgnum"] != null)
        {
            if (Utility.IsNum(base.Request["pgnum"].ToString()))
            {
                this.pagenum = base.Request["pgnum"].ToString();
            }
            else
            {
                this.SetError("您输入的参数非法");
            }
        }
        if (base.Request["consum"] != null)
        {
            this.consum = base.Request["consum"].ToString().Replace("'", "");
        }
        this.Getcoupon();
    }

}